﻿using SqlSugar;
using SqlSugarAndEntity.ConfigModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlSugarAndEntity.Base
{
    public class BaseMethod : IBaseMethod
    {
        private SqlSugarClient sqlSugarClient { get; set; }
        private SqlSugarClient GetClient()
        {
            if (sqlSugarClient == null)
            {
                sqlSugarClient= new SqlSugarClient(DataBaseConfig.GetConfig());
                sqlSugarClient.Aop.OnLogExecuted = (sql, p) =>
                {
                    Console.WriteLine($"SqlExecuteTime:[{sqlSugarClient.Ado.SqlExecutionTime}]------------------");
                    //Console.WriteLine($"SqlExecuteTime:[{db.Ado.SqlExecutionTime}]------------------");
                };
            }
            return sqlSugarClient;
        } 
        

        public SqlSugarClient Db() => GetClient();

        public IAdo Sql() => GetClient().Ado;
    }
}
